package com.ys.controller.web.storage;

import com.ys.config.MenuId;
import com.ys.dto.SubGridConfigDto;
import com.ys.entity.storage.*;
import com.ys.service.storage.TccLogisticsChannelDetailService;
import com.ys.service.sys.CommonApiService;
import com.ys.vo.W;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/web/storage/tccLogisticsChannelDetail")
public class WebTccLogisticsChannelDetailController {
	private static final Logger logger = LoggerFactory.getLogger(WebTccLogisticsChannelDetailController.class);

	@Autowired
	private CommonApiService<TccLogisticsChannelDetail> commonApiService;
	@Autowired
	private TccLogisticsChannelDetailService tccLogisticsChannelDetailService;

	private final Long MENU_ID = MenuId.TCC_LogisticsChannelDetail;

	/*
	 * 编辑
	 */
	@GetMapping("/toDetail")
	public String toEdit(Model model, HttpServletRequest request, HttpServletResponse response, String logInvoiceNo) {
		try {

			Map<String, Object> extraParam = new TccLogisticsChannelDetail()
					.addLeftJoin("TCC_Warehouse B ON B.Cck=A.Cck")
					.addLeftJoin("TCC_LogisticsServiceProvider E ON E.ProviderBid=A.ProviderCode")
					.addLeftJoin("TB_Country C ON C.Code=A.Country")

					.addField("B.Vck vck,C.Name countryName,E.Abbreviation providerName")
					.setLogInvoiceNo(logInvoiceNo)
					.queryFirstMap();


			if (extraParam == null){
				return W.error(model, "物流渠道详情不存在");
			}
			//主表信息
			//Map<String, Object> extraParam = tccLogisticsChannelDetailService.getExtraParam(bid);

			return commonApiService.toDetail(model,Long.parseLong(extraParam.get("id").toString()), new TccLogisticsChannelDetail(), MENU_ID, extraParam, null);
		}catch (Exception e) {
			logger.error("页面出错：",e.getMessage(),e);
			return W.error(model, e.getMessage());
		}
	}

}